package com.best.weiyi.thread;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.os.Bundle;
import android.os.Message;

import com.best.weiyi.entity.Song;
import com.best.weiyi.entity.SongList;

public class SongThread implements Runnable{
	private Context mContext;
	public static  List<Song> list = new ArrayList<Song>();
	public List<SongList> songList = new ArrayList<SongList>();
	public static int index = 0;
	public static Song song = list.get(index);
	public static  String path = "http://ting.baidu.com/data/music/links?songIds="+song.getSong_id()+"";
	public SongThread(String path){
		this.path= path;
	}
	@Override
	public void run() {
		// TODO Auto-generated method stub
		try {
			URL url = new URL(path);
			HttpURLConnection huc = (HttpURLConnection) url.openConnection();
			huc.setConnectTimeout(5*1000);
			huc.connect();
			switch (huc.getResponseCode()) {
			case 200:
				//运行成功
				BufferedReader br = new BufferedReader(new InputStreamReader(huc.getInputStream()));
				StringBuffer sb = new StringBuffer();
				//不会创建多余对象
				String s = "";
				while((s=br.readLine())!=null){
					sb.append(s);
				}
				Message msg = new Message();
				msg.what = 1;
				Bundle bundle = new Bundle();
				bundle.putString("songList", sb.toString().trim());
				msg.setData(bundle);
				//Search.hanlder.sendMessage(msg);
				
				break;

			default:
				break;
			}
			
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
